{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e4a8b8ab",
   "metadata": {},
   "source": [
    "# 元组(tuple)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3e870ca",
   "metadata": {},
   "source": [
    "### 语法：元组只有两个方法，count和index。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a32b3b61",
   "metadata": {},
   "source": [
    "### 知识点："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fade0717",
   "metadata": {},
   "source": [
    "* 它是和list几乎完全一样的序列数据\n",
    "* 它与list不同的地方是，不可变（因为不可变，所以几乎没有方法）\n",
    "* 元组的形式： (1,2,34,5) 对比 元组() 列表[]\n",
    "* 元组是一个一旦创建就不能改变的列表。任何情况下这个元组都不能再改变。通常可以把元组想象成一个常量列表。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3ad593ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n",
      "1\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "a = (3,2,1,4,5,2,2,4,5,6,4)\n",
    "print(type(a))\n",
    "print(a.index(2))\n",
    "print(a.count(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0839d081",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('zhichao', 'youge', 'xiaoming')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = \"zhichao\",\"youge\",\"xiaoming\"\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bb71d6d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6cdf1288",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.count(\"zhichao\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
